package com.itheima.manager;/*
 * @author  xs
 * @date 2022/1/16 13:42
 * @Version  1.0
 * */

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import com.itheima.domain.SoulTest.*;
import com.itheima.domain.vo.PageBeanVo;
import com.itheima.service.SoulTest.QuestionNaireService;
import com.itheima.service.SoulTest.SoulManagerService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.bson.types.ObjectId;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class QuestionManager {
@DubboReference
private QuestionNaireService questionNaireService;
//查询所有试题
    public ResponseEntity findByQuestion() {
        PageBeanVo pageBeanVo = new PageBeanVo();

//        查询所有试题
        List<QuestionNaire> questionNaireList = questionNaireService.findQuestionNaireList();
        ArrayList<QuestionManagerVo> voArrayList = new ArrayList<>();
        if (CollectionUtil.isNotEmpty(questionNaireList)){
            for (QuestionNaire questionNaire : questionNaireList) {

                QuestionManagerVo vo = new QuestionManagerVo();
                 vo.setId(questionNaire.getId().toHexString());
                vo.setCover(questionNaire.getCover());
                vo.setLevel(questionNaire.getLevel());
                vo.setName(questionNaire.getName());
                voArrayList.add(vo);
            }
        }
        pageBeanVo.setPage(1);//当前页码
        pageBeanVo.setPagesize(5);//页大小
        pageBeanVo.setCounts((long) questionNaireList.size());//总记录数
        System.out.println("id>>>>>>>>>>"+voArrayList);
        pageBeanVo.setItems(voArrayList);
        return ResponseEntity.ok(pageBeanVo);
    }
//  根据id 查询试题
@DubboReference
private SoulManagerService soulManagerService;
    public ResponseEntity findQuestionById(String id) {
        System.out.println("id>>>>>>>>>>"+id);
        List<QuestionNaire> questionNaireList = questionNaireService.findQuestionNaireList();



        if (StrUtil.equals(id,"1")){
            List<WJQuestion> questions1 = questionNaireList.get(0).getQuestions();

            System.out.println(">>>>>>>>>>"+questions1);
          return ResponseEntity.ok(questions1);
        }

        if (StrUtil.equals(id,"2")){
            List<WJQuestion> questions2 = questionNaireList.get(1).getQuestions();
            List<Options> options = questions2.get(2).getOptions();
            System.out.println(options+">>>>>>>>>>>>>>><<<<<<<<<<<<<");
            System.out.println(">>>>>>>>>>"+questions2);
            return ResponseEntity.ok(questions2);
        }
        if (StrUtil.equals(id,"3")) {
            List<WJQuestion> questions3 = questionNaireList.get(2).getQuestions();
            questions3.get(2).getOptions();
            System.out.println(">>>>>>>>>>"+questions3);
            return ResponseEntity.ok(questions3);
        }

        System.out.println(">..>>>>");
        return ResponseEntity.ok(null);
    }
//问题详情

    public ResponseEntity findSolution() {
        PageBeanVo pageBeanVo = new PageBeanVo();
        List<QuestionNaire> questionNaireList = questionNaireService.findQuestionNaireList();
//        题目
        List<WJQuestion> questions = questionNaireList.get(0).getQuestions();
        System.out.println(questions+"2222222");

//        选项
        pageBeanVo.setItems(questions);
//        得分
        return ResponseEntity.ok(pageBeanVo);
    }
}
